using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Sigecov.Models.Mapping
{
    public class TransportadoraMap : EntityTypeConfiguration<Transportadora>
    {
        public TransportadoraMap()
        {
            // Primary Key
            this.HasKey(t => t.traId);

            // Properties
            this.Property(t => t.traNome)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.traTipoLogradouro)
                .HasMaxLength(14);

            this.Property(t => t.traLogradouro)
                .IsRequired()
                .HasMaxLength(70);

            this.Property(t => t.traBairro)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.traComplemento)
                .HasMaxLength(40);

            this.Property(t => t.traCep)
                .IsRequired()
                .HasMaxLength(10);

            this.Property(t => t.traTelefone)
                .IsRequired()
                .HasMaxLength(14);

            this.Property(t => t.traFax)
                .HasMaxLength(14);

            this.Property(t => t.traEmail)
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("Transportadoras");
            this.Property(t => t.traId).HasColumnName("traId");
            this.Property(t => t.traNome).HasColumnName("traNome");
            this.Property(t => t.traTipoLogradouro).HasColumnName("traTipoLogradouro");
            this.Property(t => t.traLogradouro).HasColumnName("traLogradouro");
            this.Property(t => t.traNumero).HasColumnName("traNumero");
            this.Property(t => t.traBairro).HasColumnName("traBairro");
            this.Property(t => t.traComplemento).HasColumnName("traComplemento");
            this.Property(t => t.traCep).HasColumnName("traCep");
            this.Property(t => t.cidId).HasColumnName("cidId");
            this.Property(t => t.traTelefone).HasColumnName("traTelefone");
            this.Property(t => t.traFax).HasColumnName("traFax");
            this.Property(t => t.traEmail).HasColumnName("traEmail");
            this.Property(t => t.traPrecoKg).HasColumnName("traPrecoKg");

            // Relationships
            this.HasRequired(t => t.Cidade)
                .WithMany(t => t.Transportadoras)
                .HasForeignKey(d => d.cidId);

        }
    }
}
